<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%--
  Created by IntelliJ IDEA.
  User: qiliping
  Date: 16/4/8
  Time: 上午11:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>投资详情</title>
    <script src="${ctx}/assets/scripts/layer/layer.js"></script>
    <script>
        $(function () {
            $("#querenzhifu").click(function () {
                if (confirm("你确定已经支付了吗?")) {
                    var paytime = $("#pay_time").val();
                    var run_time = $("#run_time").val();
                    var end_time = $("#end_time").val();
                    if (paytime == "") {
                        alert("请填写支付时间");
                        $("#pay_time").focus();
                        return;
                    }
                    $.ajax({
                        type: "POST",
                        url: "${ctx}/ajax/audit_pay",
                        dataType: "JSON",
                        data: {id: '${investment.investmentId}', payTime: paytime, stime: run_time, etime: end_time},
                        success: function (res) {
                            if (res == 1) {
                                $("#auditPay").html("");
                                $("#tzzt").html("等待买入")
                                $("#zfzt").html("已支付(支付时间：刚刚)")
                            } else {
                                alert('时间格式不正确');
                            }

                        }
                    });
                }
            });
            <c:if test="${investment.orderStatus==1&&investment.investmentStatus==0&&product.isOpenSale==1}">
            $("#confirmButton").click(function () {
                var contractCode = $("#contractCode").val();
                var amount = $("#amount").val();
                var quantity = $("#quantity").val();
                var buyDate = $("#buyDate").val();
                if(contractCode==""){
                    layer.msg('请填写投资合同编号', {time: 2000, icon: 2});
                    $("#contractCode").focus();
                    return false;
                }
                if(amount==""){
                    layer.msg('请输入投资金额', {time: 2000, icon: 2});
                    $("#amount").focus();
                    return false;
                }
                if(isNaN(amount)){
                    layer.msg('投资金额只能是数字', {time: 2000, icon: 2});
                    $("#amount").focus();
                    return false;
                }
                if(quantity==""){
                    layer.msg('请填写买入份额', {time: 2000, icon: 2});
                    $("#quantity").focus();
                    return false;
                }
                if(isNaN(quantity)){
                    layer.msg('买入份额只能是数字', {time: 2000, icon: 2});
                    $("#quantity").focus();
                    return false;
                }
                if(buyDate==""){
                    layer.msg('请填写投资日期', {time: 2000, icon: 2});
                    $("#buyDate").focus();
                    return false;
                }
                //询问框
                layer.confirm('请确认一下投资信息：<br>客户姓名： ${investment.userName} <br>总投资金额为：￥'+amount+"元。<br>买入份额为："+quantity+"份。", {
                    title:'投资确认',
                    btn: ['确定','取消'] //按钮
                }, function(){
                    $("#ConfirmBuyModel").submit();
                    layer.msg('投资成功', {icon: 1});

                }, function(){
                    layer.msg('已经取消', {time: 2000});
                });
                return false;
            });
            </c:if>
        });

    </script>
</head>
<body>
<div class="row">
    <div class="col-md-12">
        <!-- BEGIN PAGE TITLE & BREADCRUMB-->
        <h3 class="page-title">
            投资管理
            <small>基金认购列表</small>
        </h3>
        <ul class="page-breadcrumb breadcrumb">
            <li>
                <i class="fa fa-home"></i>
                <a href="${ctx}/main">
                    首页
                </a>
                <i class="fa fa-angle-right"></i>
            </li>
            <li>
                <a href="${ctx}/invest/invest_list">
                    基金认购管理
                </a>
                <i class="fa fa-angle-right"></i>
            </li>
            <li>
                <a href="#">
                    基金认购详情
                </a>
            </li>
        </ul>
        <!-- END PAGE TITLE & BREADCRUMB-->
    </div>
</div>
<!-- END PAGE HEADER-->
<!------内容区----->
<div class="main">


    <div class="row">
        <div class="col-md-12">

            <div class="tabbable-custom ">
                <ul class="nav nav-tabs ">
                    <li class="active"><a href="javascript:void(0)">投资详情</a></li>
                </ul>
                <div class="tab-content">
                    <div id="accounts" class="tab-pane active">
                        <div class="">
                            <div class="row">
                                <c:if test="${investment.orderStatus==2}">
                                <div class="col-md-12">
                                    <div class="form-group">
                                        <label>合同编号：</label><span>${investment.contractCode}</span>
                                    </div>
                                </div>
                                </c:if>
                                <div class="col-md-12">
                                    <div class="form-group">
                                        <label>投资项目：</label><span>${investment.productName}</span>
                                    </div>
                                </div>
                                <div class="col-md-12">
                                    <h3 class="form-group">
                                        <label>当前净值：</label><span
                                            class="color_f34915">
                                                <fmt:formatNumber value="${product.currentNetValue}" type="number" maxFractionDigits="4" minFractionDigits="4" ></fmt:formatNumber>元
                                    </span>
                                    </h3>
                                </div>
                                <div class="col-md-12">
                                    <h3 class="form-group">
                                        <label>投资金额：</label><span
                                            class="color_f34915">
                                        <c:choose>
                                            <c:when test="${investment.investmentStatus==0}">
                                                <fmt:formatNumber value="${investment.orderAmount}" type="number" maxFractionDigits="4" minFractionDigits="4" ></fmt:formatNumber>元
                                            </c:when>
                                            <c:otherwise>
                                                <fmt:formatNumber value="${investment.investmentAmount}" type="number" maxFractionDigits="4" minFractionDigits="4" ></fmt:formatNumber>元
                                            </c:otherwise>
                                        </c:choose>

                                    </span>
                                    </h3>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label>投资人：</label><span>${investment.userName}</span>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label>联系手机：</label><span>${investment.userPhone}</span>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label>支付状态：</label><span id="zfzt">
                                        <c:choose>
                                            <c:when test="${investment.orderStatus==0}">
                                                未支付
                                            </c:when>
                                            <c:otherwise>
                                                已支付(支付时间:<fmt:formatDate value="${investment.orderPayTime}"
                                                                         pattern="yyyy-MM-dd"></fmt:formatDate>)
                                            </c:otherwise>
                                        </c:choose>
                                    </span>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label>投资状态：</label>
                                        <span id="tzzt">
                                         <c:choose>
                                             <c:when test="${investment.investmentStatus == 0}">
                                                 <c:choose>
                                                     <c:when test="${investment.orderStatus==0}">
                                                         未支付&nbsp;
                                                     </c:when>
                                                     <c:when test="${investment.orderStatus==1}">
                                                         等待买入
                                                     </c:when>
                                                 </c:choose>
                                             </c:when>
                                             <c:otherwise>
                                                 <c:choose>
                                                     <c:when test="${investment.investmentStatus == 0}">
                                                         等待买入
                                                     </c:when>
                                                     <c:when test="${investment.investmentStatus == 1}">
                                                         运行中
                                                     </c:when>
                                                     <c:when test="${investment.investmentStatus == 3}">
                                                         赎回中
                                                     </c:when>
                                                     <c:when test="${investment.investmentStatus == 4}">
                                                         已赎回
                                                     </c:when>
                                                     <c:when test="${investment.investmentStatus == 5}">
                                                         已结束
                                                     </c:when>
                                                 </c:choose>
                                             </c:otherwise>

                                         </c:choose>
                                        </span>
                                    </div>
                                </div>
                                <%-- <div class="col-md-3">
                                     <div class="form-group">
                                         <label>已用信用额度：</label><span>10000元</span>
                                     </div>
                                 </div>
                                 <div class="col-md-3">
                                     <div class="form-group">
                                         <label>可用信用额度：</label><span>40000元</span>
                                     </div>
                                 </div>--%>
                            </div>
                            <c:if test="${investment.orderStatus==0}">
                                <div class="row" id="auditPay">
                                    <div class="col-md-12">
                                        <div class="panel panel-default">
                                            <div class="panel-heading">
                                                <h3 class="panel-title text-center">确认支付</h3>
                                            </div>
                                            <div class="panel-body">
                                                <div class="col-md-3">
                                                    <div class="form-group">
                                                        <label>支付时间：</label>

                                                        <div class="date-control small">
                                                            <div class="input-daterange input-group">
                                                                <input type="text" id="pay_time"
                                                                       class="form-control fromdatetime col-md-3"
                                                                       size="10"/>

                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="col-md-3">
                                                    <div class="form-group">
                                                        <label>合同开始时间：</label>

                                                        <div class="date-control small">
                                                            <div class="input-daterange input-group">
                                                                <input type="text" id="run_time"
                                                                       class="form-control fromdatetime col-md-3"
                                                                       size="10"/>

                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="col-md-3">
                                                    <div class="form-group">
                                                        <label>合同结束时间：</label>

                                                        <div class="date-control small">
                                                            <div class="input-daterange input-group">
                                                                <input type="text" id="end_time"
                                                                       class="form-control fromdatetime col-md-3"
                                                                       size="10"/>

                                                            </div>
                                                        </div>

                                                    </div>
                                                </div>
                                                <div class="col-md-3" style="padding-top:23px;">
                                                    <input type="button" id="querenzhifu" class="btn blue"
                                                           value="确认支付"/>
                                                    </div>

                                            </div>
                                        </div>
                                    </div>

                                </div>
                            </c:if>
                            <c:if test="${product.isOpenSale==0}">
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="panel panel-default">
                                        <div class="panel-heading">
                                            <h3 class="panel-title text-center"></h3>
                                        </div>


                                        <div class="col-md-6">
                                            <div class="form-group">

                                                <input type="button" disabled class="btn blue" value="等待基金开放购买"/>
                                            </div>
                                        </div>

                                    </div>
                                </div>
                            </div>

                        </div>

                        </c:if>

                        <c:if test="${investment.orderStatus==1&&investment.investmentStatus==0&&product.isOpenSale==1}">

                            <div class="row">
                                <div class="col-md-12">
                                    <div class="panel panel-default">
                                        <div class="panel-heading">
                                            <h3 class="panel-title text-center">确认买入</h3>
                                        </div>
                                        <div class="panel-body">
                                            <form:form method="post" action="${ctx}/invest/confirm_buy" modelAttribute="ConfirmBuyModel"
                                                       class="form-horizontal">
                                                <form:hidden path="investId"></form:hidden>

                                                <div class="form-group">
                                                    <label class="control-label col-md-3">合同编号：</label>

                                                    <div class="col-md-3">
                                                        <div class="input-group">
                                                            <form:input path="contractCode" cssClass="form-control col-md-3"></form:input>
                                                            <form:errors path="contractCode" cssClass="field-validation-error"
                                                                         element="div"></form:errors>

                                                        </div>
                                                    </div>

                                                </div>
                                                <div class="form-group">
                                                    <label class="control-label col-md-3">买入金额：</label>

                                                    <div class="col-md-3">
                                                        <div class="input-group" id="buyAmount">
                                                            <%--<form:input path="amount" cssClass="form-control col-md-3"></form:input>--%>
                                                            <input type="text" name="amount" id="amount" class="form-control col-md-3" value="<fmt:formatNumber value="${ConfirmBuyModel.amount}" pattern="0" type="number"></fmt:formatNumber>" />
                                                            <span class="input-group-addon">元</span>
                                                            <%--<fmt:formatNumber value="${investment.orderAmount}"
                                                                              type="number" maxFractionDigits="4" minFractionDigits="4" ></fmt:formatNumber>--%>

                                                        </div>
                                                    </div>

                                                </div>
                                                <div class="form-group">
                                                    <label class="control-label col-md-3">基金净值：</label>

                                                    <div class="col-md-3">
                                                        <div class="input-group">
                                                            <%--<form:input path="netvalue" cssClass="form-control"
                                                                        maxlength="5" placeholder=""></form:input>--%>
                                                            <select name="netvalue" class="form-control col-md-3">
                                                                <c:forEach var="item" items="${netvalueList}">
                                                                    <option value="${item.netvalue}"><fmt:formatDate value="${item.calculateTime}" pattern="yyyy-MM-dd"></fmt:formatDate>  <fmt:formatNumber value="${item.netvalue}" pattern="0.0000"></fmt:formatNumber>元</option>
                                                                </c:forEach>
                                                            </select>


                                                        </div>
                                                    </div>
                                                    <%--<form:errors path="netvalue" cssClass="field-validation-error"
                                                                 element="div"></form:errors>--%>
                                                </div>
                                                <div class="form-group">
                                                    <label class="control-label col-md-3">基金份额：</label>

                                                    <div class="col-md-3">
                                                        <div class="input-group">
                                                            <input type="text" id="quantity"  name="quantity" class="form-control col-md-3" value="<fmt:formatNumber value="${ConfirmBuyModel.quantity}" pattern="0.0000" type="number"></fmt:formatNumber>" />
                                                            <span class="input-group-addon">份</span>
                                                            <%--<form:input path="quantity" cssClass="form-control"
                                                                        maxlength="12" placeholder="" pattern="0.0000" ></form:input>--%>

                                                        </div>
                                                    </div>
                                                    <form:errors path="quantity" cssClass="field-validation-error"
                                                                 element="div"></form:errors>
                                                </div>

                                                <div class="form-group">
                                                    <label class="control-label col-md-3">买入时间：</label>

                                                    <div class="col-md-3">
                                                        <div class="input-group">
                                                            <div class="input-daterange input-group">

                                                                <form:input path="buyDate" cssClass="form-control fromdatetime col-md-3"
                                                                            maxlength="12" placeholder=""></form:input>

                                                            </div>


                                                        </div>
                                                        <form:errors path="buyDate" cssClass="field-validation-error"
                                                                     element="div"></form:errors>
                                                    </div>

                                                </div>

                                                <div class="form-group">
                                                    <label class="control-label col-md-3"></label>

                                                    <div class="col-md-3">
                                                        <div class="input-group">
                                                            <input type="submit" id="confirmButton" class="btn blue" value="确认投资"/>


                                                        </div>
                                                    </div>

                                                </div>


                                            </form:form>
                                        </div>
                                    </div>
                                </div>

                            </div>
                        </c:if>
                    </div>
                </div>
            </div>
        </div>


    </div>
</div>

</div>
<!------[end]内容区----->
</body>
</html>
